Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading T1w and T2w pediatric MRI templates generated from philadelphia-pediatric dataset #9

Merged
merged 12 commits into from
Oct 15, 2023

Conversation

NadiaBlostein
Copy link
Member

@NadiaBlostein NadiaBlostein commented Sep 29, 2023

Fixes #6, Fixes #7

Screen Shot 2023-09-29 at 3 36 11 PM Screen Shot 2023-09-29 at 3 36 23 PM

…eraging more times can improve the resolution) and update this file.
…any iterations as T1w template, and will update this file. However, this template looks good as is.
@jcohenadad
Copy link
Member

@NadiaBlostein Thank you for this. My suggestion was to upload the templates as release assets, not directly in the git history. The JSON files can stay though. If you don't know how to do this I can take care of it.

@jcohenadad
Copy link
Member

jcohenadad commented Sep 29, 2023

I also noticed a few issues:

  • the nz (dim3) between T1w (dim3=687) and T2w (dim3=680) is not the same
  • the sform between T1w and T2w is not the same
pediatric-template_T1w.nii.gz
julien-macbook:~/Desktop $ fslhd pediatric-template_T1w.nii.gz 
filename	pediatric-template_T1w.nii.gz

sizeof_hdr	348
data_type	FLOAT32
dim0		3
dim1		201
dim2		201
dim3		687
dim4		0
dim5		0
dim6		0
dim7		0
vox_units	mm
time_units	Unknown
datatype	16
nbyper		4
bitpix		32
pixdim0		0.000000
pixdim1		0.500000
pixdim2		0.500000
pixdim3		0.500000
pixdim4		0.000000
pixdim5		0.000000
pixdim6		0.000000
pixdim7		0.000000
vox_offset	352
cal_max		0.000000
cal_min		0.000000
scl_slope	0.000000
scl_inter	0.000000
phase_dim	0
freq_dim	0
slice_dim	0
slice_name	Unknown
slice_code	0
slice_start	0
slice_end	0
slice_duration	0.000000
toffset		0.000000
intent		Unknown
intent_code	0
intent_name	
intent_p1	0.000000
intent_p2	0.000000
intent_p3	0.000000
qform_name	Unknown
qform_code	0
qto_xyz:1	0.500000 0.000000 0.000000 0.000000 
qto_xyz:2	0.000000 0.500000 0.000000 0.000000 
qto_xyz:3	0.000000 0.000000 0.500000 0.000000 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Left-to-Right
qform_yorient	Posterior-to-Anterior
qform_zorient	Inferior-to-Superior
sform_name	Unknown
sform_code	1
sto_xyz:1	-0.500000 0.000000 0.000000 50.250000 
sto_xyz:2	-0.000000 0.500000 0.000000 -50.250000 
sto_xyz:3	-0.000000 0.000000 0.500000 -336.818176 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Right-to-Left
sform_yorient	Posterior-to-Anterior
sform_zorient	Inferior-to-Superior
file_type	NIFTI-1+
file_code	1
descrip		mnc2nii avg.007.mnc
aux_file	
pediatric-template_T2w.nii.gz
julien-macbook:~/Desktop $ fslhd pediatric-template_T2w.nii.gz 
filename	pediatric-template_T2w.nii.gz

sizeof_hdr	348
data_type	FLOAT32
dim0		3
dim1		201
dim2		201
dim3		680
dim4		0
dim5		0
dim6		0
dim7		0
vox_units	mm
time_units	Unknown
datatype	16
nbyper		4
bitpix		32
pixdim0		0.000000
pixdim1		0.500000
pixdim2		0.500000
pixdim3		0.500000
pixdim4		0.000000
pixdim5		0.000000
pixdim6		0.000000
pixdim7		0.000000
vox_offset	352
cal_max		0.000000
cal_min		0.000000
scl_slope	0.000000
scl_inter	0.000000
phase_dim	0
freq_dim	0
slice_dim	0
slice_name	Unknown
slice_code	0
slice_start	0
slice_end	0
slice_duration	0.000000
toffset		0.000000
intent		Unknown
intent_code	0
intent_name	
intent_p1	0.000000
intent_p2	0.000000
intent_p3	0.000000
qform_name	Unknown
qform_code	0
qto_xyz:1	0.500000 0.000000 0.000000 0.000000 
qto_xyz:2	0.000000 0.500000 0.000000 0.000000 
qto_xyz:3	0.000000 0.000000 0.500000 0.000000 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Left-to-Right
qform_yorient	Posterior-to-Anterior
qform_zorient	Inferior-to-Superior
sform_name	Unknown
sform_code	1
sto_xyz:1	-0.500000 0.000000 0.000000 50.250000 
sto_xyz:2	-0.000000 0.500000 0.000000 -50.250000 
sto_xyz:3	-0.000000 0.000000 0.500000 -333.203949 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Right-to-Left
sform_yorient	Posterior-to-Anterior
sform_zorient	Inferior-to-Superior
file_type	NIFTI-1+
file_code	1
descrip		mnc2nii avg.007.mnc
aux_file	

@NadiaBlostein
Copy link
Member Author

Hi @jcohenadad,

I did not know that the two templates had to be built in the same space. Below is an overview of what I understood, to make sure we are on the same page:

Summary of the template-generation process (what I undersood)

1. An initial template space is generated based on the average length of the intervertebral levels of the subjects in the dataset of interest. It gets saved downstream as a file called template_mask.mnc.

2. The straightening and normalization method straightens all of the spinal cord images of the subjects and brings them into the same space as template_mask.mnc.

3. An iterative vowel-wise inter-subject averaging begins.

Making sure we are on the same page: details & questions

1. An initial template space is generated based on the average length of the intervertebral levels of the subjects in the dataset of interest. It gets saved downstream as a file called template_mask.mnc. CHECKPOINT 1:

  • For the T1w images of the pediatric dataset, template_mask.mnc has xyz dimensions 201 x 201 x 692.
  • For the T2w images of the pediatric dataset, template_mask.mnc has xyz dimensions 201 x 201 x 687.
  • In the pediatric dataset, the dimensions of the T1w and T2w images for the same subject are usually different (e.g. for sub-101, the recomposed T1w image is 288 x 582 x 191 whereas the recomposed T2w image is 328 x 580 x 63).
  • Therefore, it DOES make sense that template_mask.mnc for the T1w images and template_mask.mnc for the T2w images would have different dimensions and sforms. Is this correct?

2. The straightening and normalization method straightens all of the spinal cord images of the subjects and brings them into the same space as template_mask.mnc. CHECKPOINT 2 – where I think there is a bug.

  • For the T1w images of the pediatric dataset, this outputs straightened and normalized images with dimensions 201 x 201 x 687 for 5 subjects and dimensions 201 x 201 x 692 for 13 subjects. This is the step where something fishy is going on because we would expect 18 images with dimensions 201 x 201 x 692.
  • For the T2w images of the pediatric dataset, this outputs straightened and normalized images with dimensions 201 x 201 x 680 for 5 subjects and dimensions 201 x 201 x 687 for 13 subjects. This is the step where something fishy is going on because we would expect 18 images with dimensions 201 x 201 x 687.

3. The iterative vowel-wise inter-subject averaging begins.

  • For the T1w images of the pediatric dataset, this outputs a file with dimensions 201 x 201 x 687 (smallest dimensions of straightened and normalized T1w images, see Step 2).
  • For the T2w images of the pediatric dataset, this outputs a file with dimensions 201 x 201 x 680 (smallest dimensions of straightened and normalized T2w images, see Step 2).
  • Step 2 therefore needs to be fixed.

Moving forward

  1. Does it make sense now why the T1w and T2w templates would have different dimensions?

  2. I will double check that the straighten_all_subjects method of the template pipeline is where something is failing and I will open an issue on on Neuropoly/Template.

Uploaded as release asset.
Uploaded as release asset.
Minor README typo
@NadiaBlostein
Copy link
Member Author

@jcohenadad I just re-uploaded the files as release assets.

@jcohenadad
Copy link
Member

Thank you for the thorough explanation @NadiaBlostein

Does it make sense now why the T1w and T2w templates would have different dimensions?

Yes it does make sense. So I'm wondering how @benjamindeleener managed to get the same voxel and world space coordinates. @benjamindeleener can you please comment?

I will double check that the straighten_all_subjects method of the template pipeline is where something is failing and I will open an issue on on Neuropoly/Template.

Excellent-- thank you

@benjamindeleener
Copy link

I don't think they should necessarily have different sizes as both template represent and are generated from the same subjects. The way I ensured both T1w and T2w have the same size was to use only one initial template. For example, you generate the initial template using T1w along with all the labels (centerline and disks locations) and you straighten the T1w and the T2w images to this initial template. You should therefore have all the images into the same space.

Updated version of pediatric dataset to obtain from git annex
@jcohenadad
Copy link
Member

Thank you @benjamindeleener-- based on #9 (comment), I would suggest to slightly revise the method for creating the templates. In order to work iteratively though, I suggest to open an issue based on Benjamin's comments, merge this PR, and in a subsequent PR address Ben's comment

README.md Outdated Show resolved Hide resolved
Updated dataset version (now just master branch; updated commit ID), see [data-management closed issue 248](neuropoly/data-management#248 (comment))
Copy link
Member Author

@NadiaBlostein NadiaBlostein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good! I updated the dataset version in the README.

@NadiaBlostein
Copy link
Member Author

Hi @jcohenadad,

I just re-uploaded the templates – everything should be correct now, see latest release. Explanation below.

Summary of template-generation (repeated from comment above)

  1. An initial template space is generated based on the average length of the intervertebral levels of the subjects in the dataset of interest. It gets saved downstream as a file called template_mask.mnc.

  2. The straightening and normalization method straightens all of the spinal cord images of the subjects and brings them into the same space as template_mask.mnc.

  3. An iterative vowel-wise inter-subject averaging begins.

Current templates + previous error explained

  1. An initial template space is generated based on the average length of the intervertebral levels of the subjects in the dataset of interest. It gets saved downstream as a file called template_mask.mnc. CHECKPOINT 1:

    • For the T1w images of the pediatric dataset, template_mask.mnc has xyz dimensions 201 x 201 x 688.
    • For the T2w images of the pediatric dataset, template_mask.mnc has xyz dimensions 201 x 201 x 680.
  2. The straightening and normalization method straightens all of the spinal cord images of the subjects and brings them into the same space as template_mask.mnc.

    • For the T1w images of the pediatric dataset, all of the straightened images have xyz dimensions 201 x 201 x 688.
    • For the T2w images of the pediatric dataset, all of the straightened images have xyz dimensions 201 x 201 x 680.
    • ERROR EXPLAINED: The reason why this was not the case prior was due to an error on my part: the straightening and normalization has to be performed on ALL of the subjects at once such that template_mask.mnc is generated correctly. I originally performed the straightening and normalization in batches, meaning that the dimensions of template_mask.mnc were not based on an average across all subejcts. Is this clear?
  3. The iterative vowel-wise inter-subject averaging begins.

    • For the T1w images of the pediatric dataset, this outputs a file (saved as pediatric-template_T1w.nii.gz after 8 iterations) with dimensions 201 x 201 x 688.
    • For the T2w images of the pediatric dataset, this outputs a file (saved as pediatric-template_T2w.nii.gz after 8 iterations) with dimensions 201 x 201 x 680.

Moving forward

Is this clear and correct?

Thank you

@jcohenadad
Copy link
Member

Thank you @NadiaBlostein, your explanation is clear, but I think it does not address the solution that @benjamindeleener mentioned, ie: using the same target space for both contrasts (you still generate each template in its own image space).

But since the release is done, we can merge this PR and address this issue in a subsequent PR. I've opened an issue: #10

I've also added more context in the release text (under 'details'): https://github.com/spinalcordtoolbox/pediatric-template/releases/tag/r20231010

@rohanbanerjee rohanbanerjee merged commit c43f8a4 into master Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document how to create the pediatric template Create first version of template and upload as release asset
4 participants